// 7.cpp

#include "exercise.h"

class scene7 : public exerciseScene
{
public:
    scene7();

    virtual void setupScene();
    virtual void cleanScene();
    virtual void renderScene();

    void setLight0();
    void setMaterial();
    void setFrog();
};

scene7::scene7()
{

}

void scene7::setupScene()
{
    setLight0();
    setFrog();

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_FOG);
    glEnable(GL_DEPTH_TEST);

    glClearColor(0.5, 0.5, 0.5, 1.0);
}

void scene7::cleanScene()
{
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
    glDisable(GL_FOG);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0);
}

void scene7::renderScene()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-3.0, 3.0, -3.0, 3.0, 0.0, 10.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    
    setMaterial();
//     exerciseSphere sphere(1.0f, 3);
//     sphere.render();

    glBegin(GL_TRIANGLES);
    glFogCoordf(1.0);
    glVertex3f(2.0f, -2.0f, 4.0f);
    glFogCoordf(1.0);
    glVertex3f(-2.0f, 0.0f, 2.0f);
    glFogCoordf(4.0);
    glVertex3f(0.0f, 2.0f, -5.0f);
    glEnd();
}

void scene7::setLight0()
{
    GLfloat ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
    GLfloat diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
    GLfloat specular[] = {0.4f, 0.4f, 0.4f, 1.0f};
    GLfloat position[] = {0.8f, 0.8f, -1.0f, 1.0f};
    GLfloat ambientModel[] = {0.1f, 0.1f, 0.1f, 1.0f};
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientModel);
}

void scene7::setMaterial()
{
    GLfloat ambientDiffuse[] = {1.0f, 0.0f, 0.0f, 1.0f};
    GLfloat specular[] = {0.2f, 0.2f, 0.2f, 1.0f};
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambientDiffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
    glMaterialf(GL_FRONT, GL_SHININESS, 80.0f);
}

void scene7::setFrog()
{
    GLfloat color[] = {0.5f, 0.5f, 0.5f, 1.0f};
    glFogi(GL_FOG_MODE, GL_EXP);
    glFogfv(GL_FOG_COLOR, color);
    glFogf(GL_FOG_DENSITY, 0.35f);
    glHint(GL_FOG_HINT, GL_DONT_CARE);
    glFogf(GL_FOG_START, 0.0);
    glFogf(GL_FOG_END, 10.0);
}

exerciseScene* createScene7()
{
    return new scene7;
}